﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>在途</title>
		<link href="Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
		<link href="Scripts/bootstrap/css/font-awesome.css" rel="stylesheet">
		<link href="Style/skin/css/style.css" rel="stylesheet" type="text/css" />
		<link href="Style/skin/css/animate.css" rel="stylesheet" type="text/css" />
		<link href="Style/skin/font/iconfont.css" rel="stylesheet" type="text/css" />
	</head>
	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight">
						<div class="ibox-content">
							<table  class="table  table-striped">
								<thead>
									<tr>
										<th width="40">#</th>
										<th>标题(<font color=blue>注:已结束的流程,请到流程查询里找</font>)</th>
										<!--  <th>流程</th>-->
										<th width="60">发起人</th>
										<th width="70">发起部门</th>
										<!--<th>申请时间</th>-->
										<th>当前节点</th>
										<th>到达时间</th>
										<th>当前处理人</th>
										<th width="120">操作</th>
									</tr>
								</thead>
								<tbody id="Table1"></tbody>
							</table>
							<div class="row">
								<div class="col-sm-12"><span id="Table2"></span></div>
							</div>
						</div>
				
				</div>
		
		<script language="JavaScript" src="./Comm/JScript.js" type="text/javascript"></script>
		<script type="text/javascript" src="./Scripts/bootstrap/js/jquery.min.js"></script>
		<script type="text/javascript" src="./Scripts/bootstrap/js/bootstrap.min.js"></script>
		<script src="./Scripts/QueryString.js" type="text/javascript"></script>
		<script src="./Scripts/config.js" type="text/javascript"></script>
		<script src="Comm/Gener.js" type="text/javascript"></script>
		<script src="Style/skin/layui/layer.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
		
			function GroupBarClick(groupName) {

				var alt = document.getElementById('Img' + groupName).alert;
				var sta = 'block';
				if(alt == 'Max') {
					sta = 'block';
					alt = 'Min';
					classname='fa fa-minus-square';
				} else {
					sta = 'none';
					alt = 'Max';
					classname='fa  fa-plus-square';
				}

				document.getElementById('Img' + groupName).className =classname;
				document.getElementById('Img' + groupName).alert = alt;

				var i = 0;
				for(i = 0; i <= 600; i++) {

					var row = document.getElementById(groupName + i);

					if(row == null || row == undefined || row.style == null)
						continue;

					if(sta == 'block') {
						row.style.display = '';
					} else {
						row.style.display = sta;
					}
				}
			}

			// 撤销。
			function UnSend(fk_flow, workid, fid) {

				if(window.confirm('您确定要撤销本次发送吗？') == false)
					return;

				//执行撤销.
				$.ajax({
					type: 'post',
					async: true,
					url: Handler + "?DoType=Runing_UnSend&FK_Flow=" + fk_flow + "&WorkID=" + workid + "&FID=" + fid + "&m=" + Math.random(),
					dataType: 'html',
					success: function(data) {
						if(data.indexOf('err@') == 0) {
							alert(data);
							return;
						}

						$("#Msg").html(data + " <br> @点击这里<a href='javascript:window.location.href = window.location.href;' >刷新</a>");
						alert(data);
						var url = 'MyFlow.htm?FK_Flow=' + fk_flow + '&WorkID=' + workid;
						window.open(url);
						window.location.href = window.location.href;
						return;
					}
				});
			}

			//催办.
			function Press(fk_flow, workid, fid) {

				var msg = window.prompt('请输入催办信息', '该工作因为xxx原因，需要您优先处理.');
				if(msg == null)
					return;

				//执行催办.
				$.ajax({
					type: 'post',
					async: true,
					url: Handler + "?DoType=Runing_Press&Msg=" + msg + "&FK_Flow=" + fk_flow + "&WorkID=" + workid + "&FID=" + fid + "&m=" + Math.random(),
					dataType: 'html',
					success: function(data) {
						if(data.indexOf('err@') == 0) {
							alert(data);
							return;
						}

						alert(data);
						return;
					}
				});
			}

			function WinOpenIt(url) {
				
				layer.open({
				  skin: 'layer-class',	
				  type: 2, 
				  title: '在途', 
				  area:['96%','90%'],
				  content: url
				});
			}

			/* ESC Key Down */
			function Esc() {
				if(event.keyCode == 27)
					window.close();
				return true;
			}

			/* 打开表单. */
			function OpenFrm(workid, nodeID, flowNo) {

			    var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt_OneWork");
			    handler.AddUrlData();
			    handler.AddPara("FromWorkOpt", "1");
			    handler.AddPara("WorkID", workid);
			    handler.AddPara("FK_Node", nodeID);
			    handler.AddPara("FK_Flow", flowNo);
			    var data = handler.DoMethodReturnString("Runing_OpenFrm");

			    if (data.indexOf('err@') == 0) {
			        alert(data);
			        return;
			    }

			    if (data.indexOf('url@') == 0) {
			        data = data.replace('url@', '');

			        if (data.indexOf('FromWorkOpt') == -1)
			            data = data + "&FromWorkOpt=1";

			        //alert(data);

			        //window.location.href = data;
			        window.open(data);
			        return;
			    }

			    alert(data);

			}

			//页面启动函数.
			$(function() {
				InitPage();
			});

			//初始化数据.
        function InitPage() {
            //获取参数，FlowNos，为空时显示所有的待办，否则显示参数中的流程
            var flowNos = GetQueryString("FlowNos");

			    //随机串.
			    var timeKey = Math.random();

			    var handler = new HttpHandler("BP.WF.HttpHandler.WF");
			    var data = handler.DoMethodReturnString("Runing_Init");

			    if (data.indexOf('err@') == 0) {
			        alert(data);
			    }

                data = JSON.parse(data);



			    //生成分组的字符串.
			    var str = "";
			    for (var i = 0; i < data.length; i++) {
			        if (str.indexOf('@' + data[i].FlowName) == -1) {
			            if (flowNos == null || (flowNos != null && flowNos.indexOf(data[i].FK_Flow) != -1))
			                str += "@" + data[i].FlowName;
			        }

			    }
			    var strs = str.split("@"); //生成数组.

			    var num = 0;
			    var is1 = false;
			    var listbox = '';
			    //循环数组.
			    for (var idx = 0; idx < strs.length; idx++) {

			        var groupName = strs[idx];

			        if (groupName == "" || groupName == null)
			            continue;

			        listbox += "<tr  onclick=\"GroupBarClick('" + groupName + "')\" > <th colspan=8 class='table-title'> <i class='fa fa-minus-square' alert='Min'  id='Img" + groupName + "'></i><span>" + groupName + "</span></th> </tr>";


			        //增加处理.
			        for (var i = 0; i < data.length; i++) {
			            var work = data[i];
			            if (work.FlowName != groupName)
			                continue;


			            num++;

			            if (is1 == true) {
			                listbox += "<tr  id='" + groupName + num + "' >";
			                is1 = false;
			            } else {
			                listbox += "<tr  id='" + groupName + num + "' >";
			                is1 = true;
			            }

			            listbox += "<td>" + num + "</td>";
			            listbox += "<td><a href=\"javascript:OpenFrm('" + work.WorkID + "','" + work.FK_Node + "','" + work.FK_Flow + "')\" >" + work.Title + "</a></td>";
			            //  newRow += "<td>" + work.FlowName + "</td>";
			            listbox += "<td>" + work.StarterName + "</td>";
			            listbox += "<td>" + work.DeptName + "</td>";
			            //  newRow += "<td>" + work.FlowStartRDT + "</td>";
			            listbox += "<td>" + work.NodeName + "</td>";
			            listbox += "<td>" + work.RDT + "</td>";

			            var todoEmps = work.TodoEmps;

			            if (todoEmps.indexOf(',') != -1)
			                todoEmps = todoEmps.substring(todoEmps.indexOf(',') + 1);

			            listbox += "<td>" + todoEmps + "</td>";
			            listbox += "<td>";

			            listbox += "<a href=\"javascript:WinOpenIt('WFRpt.htm?FK_Flow=" + work.FK_Flow + "&FID=0&WorkID=" + work.WorkID + "&FK_Node=" + work.FK_Node + "&IsRead=0&T=" + timeKey + "');\" >查看轨迹</a>&nbsp &nbsp &nbsp<a href=\"javascript:UnSend('" + work.FK_Flow + "','" + work.WorkID + "','" + work.FID + "')\">撤销</a>";

			            // newRow += "<a href=\"javascript:Press('" + work.FK_Flow + "','" + work.WorkID + "','" + work.FID + "')\"><img src='./Img/Action/Press.png' border=0 />催办</a>";
			            listbox += "</td>";
			            listbox += "</tr>";

			        }
			    }

			    $('#Table1').html(listbox);
			    $("#Table2").html("合计:" + data.length + "条");
			}
		</script>
	</body>

</html>